package com.bawei.main

import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.common.RoutePath
import com.bawei.common.entity.VideoEntity
import com.bawei.common.mvi.BaseEvent
import com.bawei.common.mvi.BaseMviActivity
import com.bawei.home.dialog.VideoCommendFragment
import com.bawei.main.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RoutePath.PATH_MAIN)
@AndroidEntryPoint
class MainActivity : BaseMviActivity<ActivityMainBinding>() {

    private lateinit var navHostFragment: NavHostFragment
    private lateinit var navController: NavController

    override fun getLayoutId(): Int = R.layout.activity_main

    override fun initViews() {
        navHostFragment = supportFragmentManager.findFragmentById(R.id.main_nav_fragments) as NavHostFragment
        navController = navHostFragment.navController
        mDataBinding.mainBottomNav.setupWithNavController(navController)
    }

    override fun handEvent(event: BaseEvent) {
        val videoEntity = event.data as VideoEntity
        //视频评论
        if(event.type == 100){
            showVideoCommends(videoEntity)
        }
        //视频更多操作
        if(event.type == 101){
            showVideoMoreOptions(videoEntity)

        }
    }

    private fun showVideoMoreOptions(entity: VideoEntity) {

    }

    private fun showVideoCommends(entity: VideoEntity) {
        val fragment = VideoCommendFragment(entity.item_id)
        fragment.show(supportFragmentManager, "videoCommend")
    }
}